<%--
  Created by IntelliJ IDEA.
  User: B饭老司机
  Date: 2024/3/26
  Time: 12:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>check_login</title>
</head>
<body>
    <%
        String user = request.getParameter("user");
        String password = request.getParameter("password");
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://154.91.179.153:3306/db_003";
        Connection conn = DriverManager.getConnection(url, "user003", "222019#web");
        session.setAttribute("Connection",conn);
        String sql = "select * from users where username=? and password=?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1, user);
        preparedStatement.setString(2, password);
        ResultSet rs = preparedStatement.executeQuery();
        boolean isValid = false;
        if(rs.next())
            isValid = true;

        if(isValid){
            session.setAttribute("user",user);
            String url_next = "index.jsp";
            response.sendRedirect(url_next);
        }else{
            out.println("用户名或密码不正确");
            response.setHeader("refresh","3;login.jsp");
        }

    %>
</body>
</html>
